﻿
using DotNetCore.CAP;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.BLL.Order;
using SHKF.B2C.Model.Dto;
using SHKF.B2C.Model.Dto.Order;
using SHKF.B2C.Model.Entity.Order;
using SkyApm.Tracing;
using System;
using System.Collections.Generic;

namespace SHKF.B2C.Service.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class OrderController : Base2Controller
    {
        private readonly OrderBLL orderBLL;
        
        public OrderController(
              OrderBLL orderBLL,
              IServiceProvider serviceProvider,
            ILogger<OrderController> logger) : base(serviceProvider, logger)
        {
            this.orderBLL = orderBLL; 
        }


        /// <summary>
        /// 获取订单接口
        /// </summary>
        /// <param name="shopSN"></param>
        /// <param name="status"></param>
        /// <param name="create_start"></param>
        /// <param name="create_end"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public OrderListDto List(long shopSN, int status, DateTime create_start, DateTime create_end)
        {
            //定单列表 
            OrderListDto dto = new OrderListDto();
            try
            {
                List<OrderContentDto> orderList = this.orderBLL.Query(shopSN, status, create_start, create_end);
                foreach (OrderContentDto orderEntity in orderList)
                { 
                    orderEntity.Detail = this.orderBLL.QueryDetail(orderEntity.SN); 
                    orderEntity.Accounts = this.orderBLL.QueryAccounts(orderEntity.SN);
                }
                dto.data = orderList;
            }
            catch (Exception ex)
            {
                dto = new OrderListDto();
                dto.error = new Error() { code = -1, msg = ex.Message };
                base.WriteException("List", ex);
            }
            return dto;
        }

       
    }
}
